﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Edge.Common.ComponentModel.Parameters;
using Edge.Common.Services;
using Shop.Business.Domain.Catalog;

namespace Shop.Web.Controls.Ajax
{
    public partial class CatalogHtmlContent : System.Web.UI.UserControl
    {
        [QueryParameter("id", IsRequired = false)]
        public int productGroupId;

        [QueryParameter("pid", IsRequired = false)]
        public int productId;


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void OnInit(EventArgs e)
        {
            ICollection<Category> dataSource = Locator.GetService<ICategoryManager>().GetCategories(null);
            rprCatalog.DataSource = dataSource;
            rprCatalog.DataBind();
//            int i = 0;
//            foreach (Category category in dataSource)
//            {
//                GetSubCategories(category, rprCatalog,i);
//                i++;
//            }
            base.OnInit(e);
            base.OnPreRender(e);
        }

        private void GetSubCategories(Category category, Repeater parentControl, int indx)
        {
            if (category.Children != null && category.Children.Count > 0)
            {
                Repeater repeater = new Repeater();
                repeater.DataSource = category.Children;
                repeater.ItemTemplate = rprCatalog.ItemTemplate;
                repeater.DataBind();
                parentControl.Controls.Add(repeater);
                foreach (Category child in category.Children)
                {
                    GetSubCategories(child, repeater,indx);
                }
            }

        }

    }
}